import mockjs from 'mockjs';
import { chunk } from 'lodash';
import { delay } from 'roadhog-api-doc';

const { mock } = mockjs;

const TRIAL_STATUS = [
    'guideHr',
    'guideTeacher',
    'guideLeader',
    'guideComplete',
    'assessTeacherW',
    'assessLeaderW',
    'assessHRW',
    'weeklyComplete',
    'assessTeacherM',
    'assessLeaderM',
    'assessHRM',
    'monthlyComplete',
    'assessTeacherQ',
    'assessLeaderQ',
    'assessHRQ',
    'quarterlyComplete',
    'interviewReadyW',
    'interviewLogW',
    'interviewSummaryW',
    'interviewDetailW',
    'interviewReadyM',
    'interviewLogM',
    'interviewSummaryM',
    'interviewDetailM',
    'interviewReadyQ',
    'interviewLogQ',
    'interviewSummaryQ',
    'interviewDetailQ',
    'probationTerminate'
];

const INFORMAL_STATUS = ['regularApply', 'regularApproval', 'regularPass', 'approvalWithdraw', 'approvalReject'];

const RECORD_STATUS = ['regularPass', 'probationTerminate'];

// 试用中列表
const MOCK1 = mock({
    'data|78': [
        {
            id: '@natural(1, 99999)',
            employeeName: '@cname',
            'leaderPositionFlag|1': [1, 0],
            'sex|1': ['1', '2'],
            organizationName: '@cword(3, 5)',
            dutyName: '@cword(5, 8)',
            'rankValue|1': ['P5', 'P6', 'P7'],
            companyName: '@cword(3, 5)',
            entryDate: '@date',
            expectRegularDate: '@date',
            'probationPeriodNumber|1': '@natural(1, 99)',
            'probationPeriodType|1': [1, 2],
            'operateType|1': [0, 1, 2, 3],
            'workNature|1': ['full_time', 'part_time', 'practice', 'consultant', 'temporary'],
            'status|1': TRIAL_STATUS
        }
    ]
});

// 待转正列表
const MOCK2 = mock({
    'data|15': [
        {
            id: '@natural(1, 99999)',
            employeeName: '@cname',
            'leaderPositionFlag|1': [1, 0],
            'sex|1': ['1', '2'],
            organizationName: '@cword(3, 5)',
            dutyName: '@cword(5, 8)',
            'rankValue|1': ['P5', 'P6', 'P7'],
            companyName: '@cword(3, 5)',
            entryDate: '@date',
            expectRegularDate: '@date',
            'probationPeriodNumber|1': '@natural(1, 99)',
            'probationPeriodType|1': [1, 2],
            'workNature|1': ['full_time', 'part_time', 'practice', 'consultant', 'temporary'],
            'status|1': INFORMAL_STATUS
        }
    ]
});

// 历史记录列表
const MOCK3 = mock({
    'data|33': [
        {
            id: '@natural(1, 99999)',
            employeeName: '@cname',
            'leaderPositionFlag|1': [1, 0],
            'sex|1': ['1', '2'],
            organizationName: '@cword(3, 5)',
            dutyName: '@cword(5, 8)',
            'rankValue|1': ['P5', 'P6', 'P7'],
            companyName: '@cword(3, 5)',
            entryDate: '@date',
            expectRegularDate: '@date',
            'probationPeriodNumber|1': '@natural(1, 99)',
            'probationPeriodType|1': [1, 2],
            'workNature|1': ['full_time', 'part_time', 'practice', 'consultant', 'temporary'],
            'status|1': RECORD_STATUS
        }
    ]
});

const interview = {
    'GET /api/oa/v1/regular/v1/probation/interviews/prepare/*/interview_prepare': (req, res) => {
        const data = {
            probationInterviewArrangeVO: {
                cancelType: 0,
                createUser: '',
                id: 0,
                imGroupId: '',
                interviewArrangeCode: '',
                interviewEmployeeCodeList: [],
                interviewEndTime: '',
                interviewLocation: '',
                interviewStartTime: '',
                interviewStatus: 0,
                interviewType: 0,
                interviewTypeName: '',
                interviewWay: 0,
                interviewerEmployeeName: '',
                latestFlag: 0,
                operateEmployeeCode: '',
                operateEmployeeName: '',
                recordTimeInfo: '',
                recordUrl: '',
                regularProbationId: 0,
                scheduleId: 0,
                sortNo: 0,
                sourceId: 0,
                sourceType: '',
                updateUser: ''
            },
            selfInterviewQuestions: [
                {
                    id: 483,
                    arrangeId: 473,
                    question: '你喜欢抽烟嘛？',
                    createUser: 'oa1143398783065804801',
                    answer: {
                        answerContent: '',
                        recordUrl: '',
                        recordTimeInfo: ''
                    },
                    comments: [],
                    createUserName: '李贺',
                    createTime: '2021-01-15 17:24:00'
                },
                {
                    id: 484,
                    arrangeId: 473,
                    question: '2222222222222222',
                    createUser: 'oa1143398783065804801',
                    answer: {
                        answerContent: '',
                        recordUrl: '',
                        recordTimeInfo: ''
                    },
                    comments: [],
                    createUserName: '李贺',
                    createTime: '2021-01-15 17:24:00'
                }
            ],
            othersInterviewQuestions: [
                {
                    id: 487,
                    arrangeId: 473,
                    question: '你喜欢喝酒嘛？',
                    createUser: 'oa1143398787796979714',
                    answer: {
                        answerContent: '',
                        recordUrl: '',
                        recordTimeInfo: ''
                    },
                    comments: [],
                    createUserName: '张世贵',
                    createTime: '2021-01-16 16:07:54'
                },
                {
                    id: 488,
                    arrangeId: 473,
                    question: '你对于六块腹肌怎么看',
                    createUser: 'oa1143398787796979714',
                    answer: {
                        answerContent: '',
                        recordUrl: '',
                        recordTimeInfo: ''
                    },
                    comments: [],
                    createUserName: '张世贵',
                    createTime: '2021-01-16 16:07:54'
                }
            ]
        };

        res.json({ code: 10000, data });
    },
    'GET /api/oa/v1/regular/v1/probation/interviews/procedure/*/interview_procedure': (req, res) => {
        const data = {
            selfInterviewQuestions: [
                {
                    id: 483,
                    arrangeId: 473,
                    question: '你喜欢抽烟嘛？',
                    createUser: 'oa1143398783065804801',
                    answer: {
                        answerContent: '',
                        recordUrl: '',
                        recordTimeInfo: ''
                    },
                    comments: [],
                    createUserName: '李贺',
                    createTime: '2021-01-15 17:24:00'
                },
                {
                    id: 484,
                    arrangeId: 473,
                    question: '2222222222222222',
                    createUser: 'oa1143398783065804801',
                    answer: {
                        answerContent: '',
                        recordUrl: '',
                        recordTimeInfo: ''
                    },
                    comments: [],
                    createUserName: '李贺',
                    createTime: '2021-01-15 17:24:00'
                }
            ],
            othersInterviewQuestions: [
                {
                    id: 487,
                    arrangeId: 473,
                    question: '你喜欢喝酒嘛？',
                    createUser: 'oa1143398787796979714',
                    answer: {
                        answerContent: '',
                        recordUrl: '',
                        recordTimeInfo: ''
                    },
                    comments: [],
                    createUserName: '张世贵',
                    createTime: '2021-01-16 16:07:54'
                },
                {
                    id: 488,
                    arrangeId: 473,
                    question: '你对于六块腹肌怎么看',
                    createUser: 'oa1143398787796979714',
                    answer: {
                        answerContent: '',
                        recordUrl: '',
                        recordTimeInfo: ''
                    },
                    comments: [],
                    createUserName: '张世贵',
                    createTime: '2021-01-16 16:07:54'
                }
            ]
        };

        res.json({ code: 10000, data });
    },
    'GET /api/oa/v1/work/informal/candidates/talent/*': (req, res) => {
        const data = {
            talentCode: 'R21348570014057836546',
            talentName: '复制面试的数据',
            talentAvatar: '',
            talentOriginalFileUrl: '',
            talentSex: '',
            talentPhone: '16666677777',
            talentEmail: 'zhangshigui@vv.cn',
            talentNation: '',
            talentProvince: '',
            talentNativePlace: '',
            talentBirth: '',
            talentStartWorkTime: '',
            talentSchoolEntryDate: '',
            talentSchoolGraduateDate: '',
            talentGraduateSchool: '',
            talentDegree: '',
            talentProfession: '',
            lastCompany: '',
            lastPost: '',
            talentTag: '',
            phoneAreaCode: '86',
            talentIdCard: '350481199605151236',
            address: '',
            talentWorkType: 1,
            talentWorkYearNum: 0,
            backCheckAccept: '',
            lastCompanyStartTime: '',
            lastCompanyEndTime: '',
            talentChannel: 'lagou',
            talentChannelDetail: '拉勾',
            acceptDate: '2021-01-11',
            organizationCode: 'ORG1334320225080938497',
            organizationName: '开发一组',
            companyCode: 'ORG1334315084407738369',
            companyName: '微微金服科技有限公司',
            dutyCode: 'DUTY1337309069961129985',
            dutyName: '高级WEB开发工程师',
            talentAge: 0,
            resumeChannelName: '拉勾',
            positionCode: 'PS4797829663260413326',
            positionName: '高级行政专员',
            rankCode: 'RK50242109451756595',
            rankValue: 'P5',
            launchEmployeeCode: 'oa1143398783065804801',
            principalEmployeeCode: 'oa1143398787796979714',
            recruitTalentMatcherId: 1250,
            currentSalaryDesc: '',
            talentSalaryProveFileList: [],
            backgroundCheckFlag: false
        };

        res.json({ code: 10000, data });
    }
};

const proxy = {
    'POST /api/oa/v1/work/informal/get_informal_list': (req, res) => {
        const { pageSize = 10, pageNo = 1, type = '1' } = JSON.parse(req.body.params) || {};
        let obj = MOCK1;
        switch (type) {
            case '2':
                obj = MOCK2;
                break;
            case '3':
                obj = MOCK3;
                break;
            default:
                break;
        }
        const { data } = obj;

        /* 模拟分页 */
        const chunkedData = chunk(data, pageSize);

        res.json({ code: 10000, data: { rows: chunkedData[pageNo - 1], total: data.length } });
    },
    'POST /api/oa/v1/work/informal/get_informal_detail': (req, res) => {
        res.json({
            code: 10000,
            data: mock({
                id: '@natural(1, 99999)',
                employeeName: '@cname',
                'gender|1': ['1', '2'],
                organizationName: '@cword(3, 5)',
                dutyName: '@cword(5, 8)',
                companyName: '@cword(3, 5)',
                entryDate: '@date',
                'period|1': [2, 3, 6],
                'workType|1': [1, 2, 3, 4, 5],
                'status|1': [0]
            })
        });
    }
};

const next = { ...proxy, ...interview };

export default delay(next, 1000);
